<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of cartesian</title>
  <meta name="keywords" content="cartesian">
  <meta name="description" content="cartesian(g,h1,h2) --- overwrite g with the product of h1 and h2">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html &copy; 2003 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../../m2html.css">
</head>
<body>
<a name="_top"></a>
<div><a href="../../index.html">Home</a> &gt;  <a href="../index.html">matgraph</a> &gt; <a href="index.html">@graph</a> &gt; cartesian.m</div>

<!--<table width="100%"><tr><td align="left"><a href="../../index.html"><img alt="<" border="0" src="../../left.png">&nbsp;Master index</a></td>
<td align="right"><a href="index.html">Index for matgraph/@graph&nbsp;<img alt=">" border="0" src="../../right.png"></a></td></tr></table>-->

<h1>cartesian
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>cartesian(g,h1,h2) --- overwrite g with the product of h1 and h2</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>function cartesian(g,h1,h2) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre class="comment"> cartesian(g,h1,h2) --- overwrite g with the product of h1 and h2</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../../matlabicon.gif)">
<li><a href="add.html" class="code" title="function add(g,i,j)">add</a>	add --- add edge(s) to the graph</li><li><a href="clear_edges.html" class="code" title="function clear_edges(g)">clear_edges</a>	clear_edges(g) --- delete all edges of g</li><li><a href="embed.html" class="code" title="function embed(g,xy)">embed</a>	embed --- create an embedding for a graph</li><li><a href="get_label.html" class="code" title="function out = get_label(g,v)">get_label</a>	get_label(g) or get_label(g,v) --- get vertex label(s)</li><li><a href="getxy.html" class="code" title="function z = getxy(g)">getxy</a>	getxy(g) --- give g's embedding (or [] if g doesn't have one)</li><li><a href="has.html" class="code" title="function yn = has(g,u,v)">has</a>	has --- check if the graph has a particular vertex or edge</li><li><a href="hasxy.html" class="code" title="function yn = hasxy(g)">hasxy</a>	hasxy(g) --- determine if an embedding has been created for g</li><li><a href="is_labeled.html" class="code" title="function yn = is_labeled(g)">is_labeled</a>	is_labeled(g) --- determine if there are labels on vertices.</li><li><a href="label.html" class="code" title="function label(g,v,name)">label</a>	Assign labels to vertices of g</li><li><a href="nv.html" class="code" title="function n = nv(g)">nv</a>	nv(g) --- number of vertices in g</li><li><a href="resize.html" class="code" title="function resize(g, n)">resize</a>	resize(g,n) --- change the number of vertices in g to n</li></ul>
This function is called by:
<ul style="list-style-image:url(../../matlabicon.gif)">
<li><a href="cube.html" class="code" title="function cube(g,k)">cube</a>	cube(g,k) --- create a k-cube (default k = 3)</li></ul>
<!-- crossreference -->

<h2><a name="_subfunctions"></a>SUBFUNCTIONS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<ul style="list-style-image:url(../../matlabicon.gif)">
<li><a href="#_sub1" class="code">function [i,j] = splitout(k, n1, n2)</a></li></ul>
<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function cartesian(g,h1,h2)</a>
0002 <span class="comment">% cartesian(g,h1,h2) --- overwrite g with the product of h1 and h2</span>
0003 
0004 n1 = <a href="nv.html" class="code" title="function n = nv(g)">nv</a>(h1);
0005 n2 = <a href="nv.html" class="code" title="function n = nv(g)">nv</a>(h2);
0006 n = n1 * n2;
0007 
0008 <a href="resize.html" class="code" title="function resize(g, n)">resize</a>(g,n);
0009 <a href="clear_edges.html" class="code" title="function clear_edges(g)">clear_edges</a>(g);
0010 
0011 <span class="keyword">for</span> u=1:n-1
0012     <span class="keyword">for</span> v=u+1:n
0013         [u1,u2] = <a href="#_sub1" class="code" title="subfunction [i,j] = splitout(k, n1, n2)">splitout</a>(u,n1,n2);
0014         [v1,v2] = <a href="#_sub1" class="code" title="subfunction [i,j] = splitout(k, n1, n2)">splitout</a>(v,n1,n2);
0015         
0016         <span class="keyword">if</span> (u1==v1) &amp;&amp; <a href="has.html" class="code" title="function yn = has(g,u,v)">has</a>(h2,u2,v2)
0017             <a href="add.html" class="code" title="function add(g,i,j)">add</a>(g,u,v);
0018         <span class="keyword">end</span>
0019         <span class="keyword">if</span> <a href="has.html" class="code" title="function yn = has(g,u,v)">has</a>(h1,u1,v1) &amp;&amp; (u2==v2)
0020             <a href="add.html" class="code" title="function add(g,i,j)">add</a>(g,u,v);
0021         <span class="keyword">end</span>
0022     <span class="keyword">end</span>
0023 <span class="keyword">end</span>
0024 
0025 
0026 <span class="keyword">if</span> <a href="hasxy.html" class="code" title="function yn = hasxy(g)">hasxy</a>(h1) &amp;&amp; <a href="hasxy.html" class="code" title="function yn = hasxy(g)">hasxy</a>(h2)
0027     xy1 = <a href="getxy.html" class="code" title="function z = getxy(g)">getxy</a>(h1);
0028     xy2 = <a href="getxy.html" class="code" title="function z = getxy(g)">getxy</a>(h2);
0029     
0030     xy = zeros(n,4);
0031     
0032     <span class="keyword">for</span> u=1:n
0033         [u1,u2] = <a href="#_sub1" class="code" title="subfunction [i,j] = splitout(k, n1, n2)">splitout</a>(u,n1,n2);
0034         xy(u,:) = [xy1(u1,:),xy2(u2,:)];
0035     <span class="keyword">end</span>
0036     m = randn(4,2);
0037     [q,r] = qr(m);
0038     p = q(:,1:2);
0039     xy = xy*p;
0040     <a href="embed.html" class="code" title="function embed(g,xy)">embed</a>(g,xy);
0041     
0042 <span class="keyword">end</span>
0043 
0044 
0045 <span class="keyword">if</span> <a href="is_labeled.html" class="code" title="function yn = is_labeled(g)">is_labeled</a>(h1) &amp;&amp; <a href="is_labeled.html" class="code" title="function yn = is_labeled(g)">is_labeled</a>(h2)
0046     <span class="keyword">for</span> u=1:n
0047         [u1,u2] = <a href="#_sub1" class="code" title="subfunction [i,j] = splitout(k, n1, n2)">splitout</a>(u,n1,n2);
0048         lab1 = <a href="get_label.html" class="code" title="function out = get_label(g,v)">get_label</a>(h1,u1);
0049         lab2 = <a href="get_label.html" class="code" title="function out = get_label(g,v)">get_label</a>(h2,u2);
0050         <a href="label.html" class="code" title="function label(g,v,name)">label</a>(g,u, [<span class="string">'('</span>, lab1, <span class="string">','</span>, lab2, <span class="string">')'</span>]);
0051     <span class="keyword">end</span>
0052 <span class="keyword">end</span>
0053 
0054 
0055 
0056 
0057 
0058 <a name="_sub1" href="#_subfunctions" class="code">function [i,j] = splitout(k, n1, n2)</a>
0059 
0060 j = mod(k-1,n2);
0061 i = (k-1-j)/n2;
0062 <span class="comment">%i = floor((k-1)/n2);</span>
0063 
0064 i=i+1;
0065 j=j+1;</pre></div>
<hr><address>Generated on Fri 30-Apr-2010 07:51:16 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/">m2html</a></strong> &copy; 2003</address>
</body>
</html>